{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.chat_models.ollama import ChatOllama \n",
    "from langchain_core.callbacks import CallbackManager, StreamingStdOutCallbackHandler\n",
    "Chatllm = ChatOllama(model=\"qwen2:7b\", callback_manager=CallbackManager([StreamingStdOutCallbackHandler()]), verbose=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "os.environ[\"LANGCHAIN_TRACING_V2\"]='true'\n",
    "os.environ['LANGCHAIN_API_KEY']=\"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\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/anaconda3/envs/ChatTTS/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "View the evaluation results for experiment: 'sample-experiment-b6fbe115' at:\n",
      "https://smith.langchain.com/o/3940f903-2902-5ee2-b747-f2b966aabc4e/datasets/ad9dcc2e-61c3-465b-8795-45aa14cd1d6b/compare?selectedSessions=974796f5-a884-4e52-8279-6d1aaafe6270\n",
      "\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2it [00:01,  1.10it/s]\n"
     ]
    }
   ],
   "source": [
    "from langsmith import Client\n",
    "from langsmith.evaluation import evaluate\n",
    "\n",
    "client = Client()\n",
    "\n",
    "# Define dataset: these are your test cases\n",
    "dataset_name = \"Sample Dataset\"\n",
    "dataset = client.create_dataset(dataset_name, description=\"A sample dataset in LangSmith.\")\n",
    "client.create_examples(\n",
    "    inputs=[\n",
    "        {\"postfix\": \"to LangSmith\"},\n",
    "        {\"postfix\": \"to Evaluations in LangSmith\"},\n",
    "    ],\n",
    "    outputs=[\n",
    "        {\"output\": \"Welcome to LangSmith\"},\n",
    "        {\"output\": \"Welcome to Evaluations in LangSmith\"},\n",
    "    ],\n",
    "    dataset_id=dataset.id,\n",
    ")\n",
    "\n",
    "# Define your evaluator\n",
    "def exact_match(run, example):\n",
    "    return {\"score\": run.outputs[\"output\"] == example.outputs[\"output\"]}\n",
    "\n",
    "experiment_results = evaluate(\n",
    "    lambda input: \"Welcome \" + input['postfix'], # Your AI system goes here\n",
    "    data=dataset_name, # The data to predict and grade over\n",
    "    evaluators=[exact_match], # The evaluators to score the results\n",
    "    experiment_prefix=\"sample-experiment\", # The name of the experiment\n",
    "    metadata={\n",
    "      \"version\": \"1.0.0\",\n",
    "      \"revision_id\": \"beta\"\n",
    "    },\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ChatTTS",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
